package me.firstapp.service.weixin.system.impl;

import java.math.BigDecimal;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import me.firstapp.common.utils.Page;
import me.firstapp.module.weixin.system.ThisSystem;
import me.firstapp.repository.weixin.system.ThisSystemRepository;
import me.firstapp.service.weixin.system.ThisSystemService;

@Service
public class ThisSystemServiceImpl implements ThisSystemService {

	@Autowired
	private ThisSystemRepository thisSystemRepository;

	@Override
	public Page<ThisSystem> findThisSystemPage(Integer pageNo, Integer pageSize, Map<String, Object> searchParams,
			String sortParam, String sortType) {
		return thisSystemRepository.findThisSystemPage(pageNo, pageSize, searchParams, sortParam, sortType);
	}

	@Override
	public ThisSystem executeUpdate(Long id, Integer orderNoLength, Long orderOutTime, BigDecimal cashFeeRate,
			BigDecimal fansWeibiToJinbiRate, BigDecimal vipWeibiToJinbiRate, BigDecimal agenterWeibiToJinbiRate,
			BigDecimal partnerWeibiToJinbiRate, Integer partnerCountsLimit, BigDecimal partnerJinbiFromAgentCashRate,
			BigDecimal spreadGiveWeiBi, BigDecimal spreadGiveJinBi) {
		ThisSystem thisSystem = (ThisSystem) thisSystemRepository.getById(id);
		if (null != orderNoLength) {
			thisSystem.setOrderNoLength(orderNoLength);
		}
		if (null != orderOutTime) {
			thisSystem.setOrderOutTimes(orderOutTime);
		}
		if (null != cashFeeRate) {
			thisSystem.setCashFeeRate(cashFeeRate);
		}
		if (null != fansWeibiToJinbiRate) {
			thisSystem.setFansWeibiToJinbiRate(fansWeibiToJinbiRate);
		}
		if (null != vipWeibiToJinbiRate) {
			thisSystem.setVipWeibiToJinbiRate(vipWeibiToJinbiRate);
		}
		if (null != agenterWeibiToJinbiRate) {
			thisSystem.setAgenterWeibiToJinbiRate(agenterWeibiToJinbiRate);
		}
		if (null != partnerWeibiToJinbiRate) {
			thisSystem.setPartnerWeibiToJinbiRate(partnerWeibiToJinbiRate);
		}
		if (null != partnerCountsLimit) {
			thisSystem.setPartnerCountsLimit(partnerCountsLimit);
		}
		if (null != partnerJinbiFromAgentCashRate) {
			thisSystem.setPartnerJinbiFromAgentCashRate(partnerJinbiFromAgentCashRate);
		}
		if (null != spreadGiveWeiBi) {
			thisSystem.setSpreadGiveWeiBi(spreadGiveWeiBi);
		}
		if (null != spreadGiveJinBi) {
			thisSystem.setSpreadGiveJinBi(spreadGiveJinBi);
		}
		thisSystemRepository.update(thisSystem);
		return thisSystem;
	}

	@Override
	public ThisSystem findThisSystemById(Long id) {
		return (ThisSystem) thisSystemRepository.getById(id);
	}

	@Override
	public ThisSystem findThisSystem() {
		return thisSystemRepository.findThisSystem();
	}

}
